package com.zenchn.aspect.service;

import com.zenchn.model.TSysCriticalOperatingLog;
import com.zenchn.model.TSysLoginAccessRecord;
import com.zenchn.service.CriticalOperatingLogService;
import com.zenchn.service.LoginAccessRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @author panbingqi
 * @date 2021-06-01
 */
@Service
public class BuildSaveLogService {

    private static final Logger log = LoggerFactory.getLogger(BuildSaveLogService.class);



    @Resource
    private LoginAccessRecordService loginAccessRecordService;

    @Resource
    private CriticalOperatingLogService criticalOperatingLogService;


//    /**
//     * 异步处理保存操作日志
//     * @param accessLog
//     */
//    @Async
//    public  void saveAccessLog(WebPlatformAccessLog accessLog) {
//        try {
//            // 保存数据库
//            webPlatformAccessLogService.insert(accessLog);
//        } catch (Exception exp) {
//            // 记录本地异常日志
//            log.error("操作日志保存异常:{}", exp.getMessage());
//            exp.printStackTrace();
//        }
//    }
    @Async
    public void saveLoginAccessRecord(TSysLoginAccessRecord record) {
        try {
            loginAccessRecordService.insert(record);
            log.info("登录访问记录:{}",record.toString());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("访问记录保存异常：{}", e.getMessage());
        }
    }



    @Async
    public void saveCriticalOperatingLog(TSysCriticalOperatingLog operatingLog) {
        try {
            criticalOperatingLogService.insert(operatingLog);
            log.info("关键操作日志记录:{}",operatingLog.toString());
        } catch (Exception e) {
            e.printStackTrace();
            log.error("关键操作日志异常：{}", e.getMessage());
        }
    }

}
